package main

import (
	"fmt"
	"math/rand"
	"time"
)

/*
1.随机初始化两个8*5的矩阵，求两个矩阵的和（逐元素相加）
2.给定月份，判断属于哪个季节。分别用if和switch实现
3.创建一个student结构体，包含姓名和语数外三门课的成绩。
  用一个slice容纳一个班的同学，求每位同学的平均分和整个班三门课的平均分，全班同学平均分低于60的有几位
*/

type Student struct {
	Name    string
	Chinese int
	Math    int
	English int
}

type Class []Student

func Question1() {
	matrix_A := [8][5]int{}
	matrix_B := [8][5]int{}

	rand.Seed(time.Now().Unix())

	for i := 0; i < 8; i++ {
		for j := 0; j < 5; j++ {
			matrix_A[i][j] = rand.Intn(500)
			matrix_B[i][j] = rand.Intn(500)
		}
	}

	matrix_sum := [8][5]int{}

	for i := 0; i < 8; i++ {
		for j := 0; j < 5; j++ {
			matrix_sum[i][j] = matrix_A[i][j] + matrix_B[i][j]
		}
	}

	for _, ele := range matrix_sum {
		fmt.Printf("[")
		for _, val := range ele {
			fmt.Printf(" %d ", val)
		}
		fmt.Println("]")
	}
}

func Question2ForIf(mon int) string {
	if mon > 12 || mon < 1 {
		return "月份不存在"
	}

	if mon == 1 || mon == 2 || mon == 3 {
		return "春季"
	} else if mon == 4 || mon == 5 || mon == 6 {
		return "夏季"
	} else if mon == 7 || mon == 8 || mon == 9 {
		return "秋季"
	} else {
		return "冬季"
	}
}

func Question2ForSwitch(mon int) string {
	switch mon {
	case 1, 2, 3:
		return "春季"
	case 4, 5, 6:
		return "夏季"
	case 7, 8, 9:
		return "秋季"
	case 10, 11, 12:
		return "冬季"
	default:
		return "月份不存在"
	}
}

func Question3() {
	// class := Class{}
	class := make(Class, 0, 10)
	name := 'A'

	rand.Seed(time.Now().Unix())
	//添加10名学生
	for i := 0; i < 10; i++ {
		stu := Student{}
		stu.Name = string(name)
		name += 1
		stu.Chinese = rand.Intn(100)
		stu.Math = rand.Intn(100)
		stu.English = rand.Intn(100)
		class = append(class, stu)
	}

	var chinese_sum int
	var math_sum int
	var english_sum int
	var count int = 0
	for i := 0; i < len(class); i++ {
		chinese_sum += class[i].Chinese
		math_sum += class[i].Math
		english_sum += class[i].English
		avg := (class[i].Chinese + class[i].Math + class[i].English) / 3
		if avg < 60 {
			count++
		}
		fmt.Printf("同学%s的平均分是%d\n", class[i].Name, avg)
	}

	fmt.Printf("班级语文平均分为%d\n", chinese_sum/len(class))
	fmt.Printf("班级数学平均分为%d\n", math_sum/len(class))
	fmt.Printf("班级英语平均分为%d\n", english_sum/len(class))
	fmt.Printf("平均分低于60分的同学有%d位\n", count)
}

func main() {
	Question1()
	fmt.Println("*****************************")
	res := Question2ForIf(6)
	fmt.Println(res)
	res = Question2ForSwitch(11)
	fmt.Println(res)
	fmt.Println("*****************************")
	Question3()
}
